package space.sakana.edusysback.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import space.sakana.edusysback.entity.question.Question;
import space.sakana.edusysback.result.Result;
import space.sakana.edusysback.service.QuestionService;


@RestController
@RequestMapping("/api/question")
public class QuestionController {

    private QuestionService questionService;

    @Autowired
    public void autowiredService(QuestionService questionService){
        this.questionService = questionService;
    }

    @RequestMapping("/all")
    public Result getAllQuestion(HttpServletRequest request, HttpServletResponse response){
        return questionService.getAllQuestion(request ,response);
    }

    /**
     * 获取subject内的所有题目
     * @param sid subject id
     */
    @RequestMapping("/subject/{sid}")
    public Result getSubjectQuestions(@PathVariable int sid, HttpServletRequest request, HttpServletResponse response){
        return questionService.getSubjectQuestions(sid, request, response);
    }

    /**
     * 获取paper内的所有题目
     * @param pid paper id
     */
    @RequestMapping("/paper/{pid}")
    public Result getPaperQuestions(@PathVariable int pid, HttpServletRequest request, HttpServletResponse response){
        return questionService.getPaperQuestions(pid, request, response);
    }

    /**
     * 获取question
     * @param qid question id
     */
    @RequestMapping("/{qid}")
    public Result getQuestion(@PathVariable int qid, HttpServletRequest request, HttpServletResponse response){
        return questionService.getQuestion(qid, request, response);
    }

    @RequestMapping("/delete/{qid}")
    public Result deleteQuestion(@PathVariable int qid, HttpServletRequest request, HttpServletResponse response){
        return questionService.deleteQuestion(qid, request, response);
    }

    /**
     * 获取question
     * @param qid question id
     */
    @RequestMapping("/full/{qid}")
    public Result getFullQuestion(@PathVariable int qid, HttpServletRequest request, HttpServletResponse response){
        return questionService.getFullQuestion(qid, request, response);
    }

    /**
     * 添加单选question
     * @param data question json
     */
    @RequestMapping("/add/a")
    public Result addQuestionA(@RequestParam String data, @RequestParam int diff, HttpServletRequest request, HttpServletResponse response){
        return questionService.addQuestionA(data, diff, request, response);
    }

    /**
     * 添加多选question
     * @param data question json
     */
    @RequestMapping("/add/b")
    public Result addQuestionB(@RequestParam String data, @RequestParam int diff, HttpServletRequest request, HttpServletResponse response){
        return questionService.addQuestionB(data, diff, request, response);
    }

    /**
     * 添加判断question
     * @param data question json
     */
    @RequestMapping("/add/c")
    public Result addQuestionC(@RequestParam String data, @RequestParam int diff, HttpServletRequest request, HttpServletResponse response){
        return questionService.addQuestionC(data, diff, request, response);
    }

    /**
     * 添加简答question
     * @param data question json
     */
    @RequestMapping("/add/d")
    public Result addQuestionD(@RequestParam String data, @RequestParam int diff, HttpServletRequest request, HttpServletResponse response){
        return questionService.addQuestionD(data, diff, request, response);
    }

    /**
     * 修改question
     * @param data question json
     */
    @RequestMapping("/update")
    public Result updateQuestion(@RequestParam String data, HttpServletRequest request, HttpServletResponse response){
        return questionService.updateQuestion(data, request, response);
    }

    /**
     * 修改question
     * @param data question json
     */
    @RequestMapping("/update/base/{type}")
    public Result updateBaseQuestion(@RequestParam String data, @PathVariable int type, HttpServletRequest request, HttpServletResponse response){
        return questionService.updateBaseQuestion(type, data, request, response);
    }

}
